<template>
    <view>
        <view style="margin: 50rpx 20rpx;">
			<uni-easyinput suffixIcon="search" v-model="inputName" placeholder="输入书名搜索" @iconClick="search"></uni-easyinput>
        </view>
        <picker-view v-if="visible" :indicator-style="indicatorStyle" :value="value" @change="bindChange" class="picker-view">
            <picker-view-column>
                <view class="item" v-for="(item,index) in list" :key="index" @click="confirmBook(item.id,item.name)">{{item.name}}</view>
            </picker-view-column>
        </picker-view>
    </view>
</template>

<script setup>
import { ref } from 'vue';
import {onReady} from "@dcloudio/uni-app"
import {baseUrl} from '../../static/js/util.js'
	let visible=ref(true)
	let list=ref([
	])
	let inputName="";
	let pageSize=10;
	let pageNo=1;
	function search(){
		let params={
			pageNo,
			pageSize,
			'name':inputName
		}
		uni.request({
			url:baseUrl+"/book/list",
			data:params,
			success:res=>{
				if(res.data.code=='503'){
					uni.showToast({
						icon:'error',
						title:'请先登录'
					})
					setTimeout(() => {
						uni.switchTab({
							url: "/pages/login/login"
						})
					}, 1000)
				}
				else if(res.data.code==200){
					list.value=[]
					res.data.data.result.forEach(item=>{list.value.push(item)})
				}
			}
		})
	}
	
	function confirmBook(bookId,bookName){
		sessionStorage.setItem("selectBookId",bookId)
		sessionStorage.setItem("selectBookName",bookName)
		uni.navigateBack({
			url:'/pages/add/add?bookId='+bookId+'&bookName='+bookName
		})
	}
	
	onReady(()=>{
		search()
	})
</script>

<style lang="scss" scoped>
.picker-view {
		width: 750rpx;
		height: 600rpx;
		margin-top: 20rpx;
	}
	.item {
		line-height: 100rpx;
		text-align: center;
	}
</style>
